package com.xuecheng.content.api;

import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.service.CourseTeacherService;
import com.xuecheng.content.model.dto.CourseTeacherResultDto;
import com.xuecheng.content.model.dto.CourseTeacherDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@Api(value ="教师计划接口",tags = "教师计划接口管理")
public class CourseTeacherController {

    @Autowired
    private CourseTeacherService courseTeacherService;

    @ApiOperation("查询单个课程计划的所有教师")
    @GetMapping("/courseTeacher/list/{courseId}")
    public PageResult<CourseTeacherResultDto> selectCourseTeacher(@PathVariable Long courseId, PageParams pageParams){
        return courseTeacherService.selectCourseTeacher(courseId,pageParams);
    }

    @ApiOperation("添加教师")
    @PostMapping("/courseTeacher")
    public CourseTeacherResultDto createCourseTeacher(@RequestBody CourseTeacherDto courseTeacherDto){
        return courseTeacherService.createOrUpdateCourseTeacher(courseTeacherDto);
    }

    @ApiOperation("获取教师详细信息")
    @PostMapping("/courseTeacher/{teacherId}")
    public CourseTeacherResultDto getCourseTeacherById (@PathVariable Long teacherId){
        return courseTeacherService.getCourseTeacherById(teacherId);
    }

    @ApiOperation("删除教师")
    @DeleteMapping("/courseTeacher/course/{courseId}/{teachId}")
    public void deleteCourseTeacher(@PathVariable Long courseId,@PathVariable Long teachId){
        courseTeacherService.deleteCourseTeacher(courseId,teachId);
    }

    @ApiOperation("根据教师Id获取文件MD5值")
    @PostMapping("/courseTeacher/uploadImage/{teacherId}")
    public Map<String,String> courseTeacherExtractMd5(@PathVariable Long teacherId){
        return courseTeacherService.courseTeacherIdExtractMd5(teacherId);
    }

    @PostMapping("/courseTeacher/{teacherId}/picture")
    public Boolean updateCourseTeacherPicture( @PathVariable("teacherId") Long teacherId,  @RequestParam("picUrl") String picUrl){
        return courseTeacherService.updateCourseTeacherPicture(teacherId,picUrl);
    }

}
